unit clsNumero;

interface

uses Dm,dbtables,biblio, SysUtils;

type
  TNumero=Class(TObject)
    private
      Serie         : String;
    public
      Sequencia     : Double;
      function  Gravar(p_serie:String):Byte;
      function  Recuperar(p_serie:String):Byte;
  end;

implementation


function TNumero.Gravar;

var tq:TQuery;

begin
  tq:=Tquery.Create(dm.DmInt);
  tq.databasename:= dm.dmint.Db.DatabaseName;
  tq.active:=False;
  tq.sql.clear;
  tq.params.clear;
  tq.sql.add('SELECT * FROM Numero where Serie=:k_serie');
  tq.parambyname('k_serie').asstring:=p_serie;
  tq.open;
  if tq.eof then begin
    tq.sql.clear; tq.params.clear;
    tq.sql.add('INSERT INTO Numero VALUES('+
      ':k_Serie,'+
      ':k_Sequencia)');
  end else begin
    tq.sql.clear; tq.params.clear;
    tq.sql.add('UPDATE Numero SET '+
      'Sequencia     =:k_Sequencia '+
      'where Serie=:k_Serie');
  end;
  tq.parambyname('k_Serie').asstring    := p_serie;
  tq.parambyname('k_Sequencia').asfloat := sequencia;
  tq.close;
  try
    tq.execsql;
    result:=1;
  except
    result:=0;
  end;
  tq.Free;
end;


function TNumero.Recuperar;

var tq:TQuery;

begin
  tq:=Tquery.Create(dm.dmint);
  tq.databasename:=DmInt.Db.DatabaseName;
  tq.active:=False;
  tq.sql.clear;
  tq.sql.add('SELECT * FROM Numero where Serie=:k_Serie');
  tq.parambyname('k_Serie').asstring:=p_serie;
  tq.open;
  Serie       :=p_serie;
  if tq.eof then begin
      Sequencia := 0;
      Result:=0;
  end else begin
      Sequencia := tq.fieldbyname('Sequencia').asfloat;
      Result:=1;
  end;
  tq.Close;
  tq.Free;
end;

end.

